﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace InnovTech.Util.Crypto
{
    public class RijndaelCryptor : StreamCryptor
    {
        /// <summary>
        /// Represents a Rijndael algorithm.
        /// </summary>
        private Rijndael alg;

        /// <summary>
        /// Represents a byte[] generator to product the key and vector for the Rijndael algorithm.
        /// </summary>
        private PasswordDeriveBytes pdb = new PasswordDeriveBytes("{3BE371EA-C12E-4D5C-A7FB-C4A67D045F77}",
                                        new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 
                                                        0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

        public override SymmetricAlgorithm Algo
        {
            get
            {
                if (alg == null)
                {
                    alg = Rijndael.Create();
                    alg.Key = GetKey();
                    alg.IV = GetVector();
                }
                return alg;
            }
        }


        

        protected virtual byte[] GetKey()
        {
            return pdb.GetBytes(32);
        }

        protected virtual byte[] GetVector()
        {
            return pdb.GetBytes(16); 
        }
    }
}
